/*
 * PreferenceSet.java
 *
 * Created on December 31, 2005, 4:12 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.jxta.myjxta.util.preferences;

import java.awt.Container;
import net.jxta.myjxta.MyJXTA;
import java.util.logging.Logger;

/**
 *
 * @author polo
 */
public abstract class PreferenceSet {
    private static final Logger LOG = Logger.getLogger(PreferenceSet.class.getName());
    
    /** the root part of the fully qualified path */
    private String rootPath = null;
    
    private static final String SEP = MyPreferenceManager.SEP;
    
    private static final String PREFERENCE = MyPreferenceManager.PREFERENCE;
    protected static MyPreferenceManager prefMan =  null;
    protected static MyJXTA myjxta = null;
    
    public static final String ATTRIBUTE_NAME = MyPreferenceManager.ATTRIBUTE_NAME;
    public static final String ATTRIBUTE_DESCRIPTION = MyPreferenceManager.ATTRIBUTE_DESCRIPTION;
    public static final String ATTRIBUTE_VISIBLE = MyPreferenceManager.ATTRIBUTE_VISIBLE;
    public static final String ATTRIBUTE_LABEL = MyPreferenceManager.ATTRIBUTE_LABEL;
    public static final String ATTRIBUTE_VALUE = MyPreferenceManager.ATTRIBUTE_VALUE;
    public static final String ATTRIBUTE_ENABLE = MyPreferenceManager.ATTRIBUTE_ENABLE;
    public static final String ATTRIBUTE_ICON = MyPreferenceManager.ATTRIBUTE_ICON;
    public static final String ATTRIBUTE_TOOLTIP = MyPreferenceManager.ATTRIBUTE_TOOLTIP;
    public static final String ATTRIBUTE_CLASS = MyPreferenceManager.ATTRIBUTE_CLASS;
    
    
    /** Creates a new instance of PreferenceSet */
    protected PreferenceSet() {
        
        prefMan = MyPreferenceManager.getInstance();
        myjxta = prefMan.getMyJxta();
    }
    
    public abstract void destroy();

    public abstract Container getUI();
    
    public abstract void init();
    
    public final String getRootPath() {
        return rootPath;
    }
    
    public final void setRootPath(String rootPath) {
        this.rootPath = rootPath;
    }
    
    
    public final void setPreferece(String prefName, String value) {
        
        MyPreferenceManager.getInstance().setPreference(rootPath+SEP+PREFERENCE+"[@name=\""+prefName+"\"]", value);
    }
    
    public final void setPreferece(String prefName, String attrName, String value) {
        
        MyPreferenceManager.getInstance().setPreference(rootPath+SEP+PREFERENCE+"[@name=\""+prefName+"\"]"+SEP+"@"+attrName, value);
    }
    
    public final String getPreference(String prefName) {
        
        
        String path = rootPath+SEP+PREFERENCE+"[@name=\""+prefName+"\"]";
        String value = MyPreferenceManager.getInstance().getPreference(path);
        
        return value;
    }
    
    public final String getAttribute(String attr) {
        
        return MyPreferenceManager.getInstance().getAttribute(rootPath,attr);
    }
    
    public final String getPreferenceAttribute(String prefName, String attr) {
        
        return MyPreferenceManager.getInstance().getAttribute(rootPath+SEP+PREFERENCE+"[@name=\""+prefName+"\"]",attr);
    }
    
    public final boolean preferenceExists(String preferenceName) {
        boolean ret = false;
        
        String name = getPreferenceAttribute(preferenceName, ATTRIBUTE_NAME);
        
        if(name != null) {
            ret = true;
        }
        
        return ret;
    }
    
    
    
    
}
